<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">未入库</li>
        <li>已入库</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <div class="layui-fluname">
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline" name="pageName"></div>
                            <div class="layui-inline">
                                <input type="text" id="entityNameNot" placeholder="请输入订单号/供应商" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <!-- 搜索按钮 -->
                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-list" id="entity_searchNot">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <table id="entityTableNot" lay-filter="entityTableNot"></table>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="layui-fluname">
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline" name="pageName"></div>
                            <div class="layui-inline">
                                <input type="text" id="entityNameYes" placeholder="订单号/关联订单号/操作员"
                                       autocomplete="off" class="layui-input">
                            </div>
                            <!-- 搜索按钮 -->
                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-list" id="entity_searchYes">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <table id="entityTableYes" lay-filter="entityTableYes"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../js/jquery-1.8.3.min.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    //路径配置 - 手动填写
    var findPageURLNot = "/depotInOrder/findPage";
    var findPageURLYes = "/depotInOrder/findPageYes";
    var addURL = "/depotInOrder/add";
    var toUpdateURL = "/depotInOrder/findOne";
    var updateURL = "/depotInOrder/update";
    var deleteURL = "/depotInOrder/delete";
    var detailsYesURL = "/depotInOrder/findYesDetails";
    //页面配置 - 不用填写
    var entityType = "";
    var entityURL = "";
    var entityId = "";

    //layui配置
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table', 'util'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , layer = layui.layer
            , util = layui.util;

        //监听未入库搜索
        $("#entity_searchNot").on('click', function (data) {
            //执行重载
            table.reload('entityTableNot', {
                method: 'post'
                , where: {
                    "ordernumber": $("#entityNameNot").val()
                }
                , page: {curr: 1}
            });
        });

        //未入库表格执行渲染
        table.render({
            elem: '#entityTableNot'
            , name: 'entityTableNot'
            , url: findPageURLNot
            , toolbar: true
            , page: true
            , limits: [10, 20, 30, 50]
            , cols: [[
                {fixed: 'left', field: 'ordernumber', width: 160, title: '单据编号'}
                , {field: 'suname', title: '供应商'}
                , {field: 'apply', title: '进货员'}
                , {field: 'buycount', title: '待入库量'}
                , {field: 'remark', title: '备注'}
                , {
                    field: 'is_status', title: '状态', width: 80, templet: function (d) {
                        if (d.is_status == "1") return "<span class=\"layui-badge\">未入库</span>\n"
                        else if (d.is_status == "2") return "<span class=\"layui-badge  layui-bg-orange\">部分入库</span>\n"
                        else if (d.is_status == "3") return "<span class=\"layui-badge layui-bg-green\">已入库</span>\n"
                    }
                }
                , {
                    field: 'gmt_create', width: 160, title: '制单日期',
                    templet: function (d) {
                        return util.toDateString(d.gmt_create, 'yyyy-MM-dd HH:mm:ss')
                    }
                }
                , {
                    fixed: 'right', title: '操作', align: 'center', templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="details">查看</a>';
                        html += '<a class="layui-btn layui-btn-xs" lay-event="inDepot">入库</a>'
                        return html;
                    }
                }
            ]]
            , where: {
                "ordernumber": $("#entityNameNot").val()
            }
        });

        //监听未入库行工具事件
        table.on('tool(entityTableNot)', function (obj) { //注：tool 是工具条事件名，zq_table 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (layEvent) {
                case 'details':
                    entityType = "toDetail";
                    entityURL = updateURL;
                    entityId = data.id;
                    var layerDetail = layer.open({
                        type: 2
                        , title: "查询入库单"
                        , content: 'form.html'
                        , resize: false
                        , area: ['850px', '500px']
                        , scrollbar: false
                        , btn: ['关闭']
                        , end: function () {
                            entityType = "";
                        }
                    });
                    layer.full(layerDetail);
                    break;
                case 'inDepot':
                    entityType = "inDepot";
                    entityURL = addURL;
                    entityId = data.id;
                    var layerinDepot = layer.open({
                        type: 2
                        , title: "新增入库单"
                        , content: 'form.html'
                        , resize: false
                        , area: ['850px', '500px']
                        , scrollbar: false
                        , btn: false
                        , closeBtn: 0
                        , end: function () {
                            entityType = "";
                        }
                    });
                    layer.full(layerinDepot);
                    break;
            }
        });

        //监听已入库搜索
        $("#entity_searchYes").on('click', function (data) {
            //执行重载
            table.reload('entityTableYes', {
                method: 'post'
                , where: {
                    "ordernumber": $("#entityNameYes").val()
                }
                , page: {curr: 1}
            });
        });
        //已入库表格执行渲染
        table.render({
            elem: '#entityTableYes'
            , name: 'entityTableYes'
            , url: findPageURLYes
            , page: true
            , toolbar: true
            , limits: [10, 20, 30, 50]
            , cols: [[
                {fixed: 'left', field: 'ordernumber', width: 160, title: '单据编号'}
                , {field: 'pordernumber', width: 160, title: '关联单据'}
                , {field: 'suname', title: '供应商'}
                , {field: 'apply', title: '入库员'}
                , {field: 'buycount', title: '入库量'}
                , {field: 'remark', title: '备注'}
                , {
                    field: 'gmt_create', width: 160, title: '制单日期',
                    templet: function (d) {
                        return util.toDateString(d.gmt_create, 'yyyy-MM-dd HH:mm:ss')
                    }
                }
                , {
                    fixed: 'right', title: '操作', width: 120, align: 'center', templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="details">查看</a>';
                        return html;
                    }
                }
            ]]
            , where: {
                "ordernumber": $("#entityNameYes").val()
            }
        });
        //监听已入库行工具事件
        table.on('tool(entityTableYes)', function (obj) { //注：tool 是工具条事件名，zq_table 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (layEvent) {
                case 'details':
                    entityType = "toDetails";
                    entityURL = detailsYesURL;
                    entityId = data.id;
                    var layerDetail = layer.open({
                        type: 2
                        , title: "查询入库单"
                        , content: 'form.html'
                        , resize: false
                        , area: ['850px', '500px']
                        , scrollbar: false
                        , btn: ['关闭']
                        , end: function () {
                            entityType = "";
                        }
                    });
                    layer.full(layerDetail);
                    break;
            }
        });

        //必备
        $('.layui-btn.layuiadmin-btn-role').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>

